<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>信息修改</title>
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width,initial-scale=1">
    <link rel="stylesheet" href="css/common.css">
    <link rel="stylesheet" href="css/personalCenter.css">
</head>
<body>
<!------IE浏览器判断------>
<!--[if lt IE 9]>
<script type="text/javascript" src="https://cdn.bootcss.com/html5shiv/3.7.3/html5shiv.min.js">
</script>
<![endif]-->

<jsp:include page="head.jsp"></jsp:include>
<!------主内容区------>
<div class="main">
    <div class="poistion">
        <h4 class="clearfix">
            <span class="icon icon1"></span><span> 首页 > 个人中心 >修改信息</span>
        </h4>
    </div>
    <div id="aside">
        <div class="aside-title">
            <h3>个人中心</h3>
        </div>
        <div class="aside-content">
            <ul class="itemlist">
                <li class="item"><a href="personlCenter.jsp">基本信息</a><span class="icon2"></span></li>
                <li class="item"><a href="personalChange.jsp">修改信息</a><span class="icon2"></span></li>
                <li class="item"><a href="changePassword.jsp">修改密码</a><span class="icon2"></span></li>
                <li class="item"><a href="replacement.jsp">会员升级</a><span class="icon2"></span></li>
            </ul>
        </div>
    </div>
    <div class="modal" id="newsLis">
        <div id="newsList">
            <div class="newsList-content">
                <div class="newsList-title">
                    <h3 class="pull-left left">信息修改</h3>
                    <i></i>
                </div>
                <div class="newList-main">
                    <div class="forms">
                        <form action="company_update" enctype="multipart/form-data" method="post" id="formId">
                        	<input type="hidden" name="company.comp_id" value="${comp.comp_id }">
                        	<input type="hidden" name="profile.pro_license" value="${comp.profile.pro_license }">
                        	<input type="hidden" name="profile.pro_id" value="${comp.profile.pro_id }">
                            <table>
                                <tr>
                                    <th><span>*</span>企业名称：</th>
                                    <td><input type="text" id="username" name="company.comp_name" placeholder="请输入企业名称"
                                               onblur="checkUser()"      value="${comp.comp_name }">
                                        <input type="hidden" id="username2" value="${comp.comp_name }">
                                    </td>
                                    <td class="warning" id="username-warn"></td>
                                </tr>
                                <tr>
                                    <th><span>*</span>企业代码：</th>
                                    <td><input type="text" name="company.comp_code" id="usercode" placeholder="请输入企业注册代码"
                                               onblur="userCode()" value="${comp.comp_code }">
                                        <input type="hidden" id="usercode2" value="${comp.comp_code }">
                                    </td>
                                    <td class="warning" id="usercode-warn"></td>
                                </tr>
                                <tr>
                                    <th><span>*</span>联系方式：</th>
                                    <td><input type="text" id="userphone" name="profile.pro_phone" placeholder="请输入相关人员手机号" onblur="userPhone()" value="${comp.profile.pro_phone }">

                                    </td>
                                    <td class="warning" id="userphone-warn"></td>
                                </tr>
                                <tr>
                                    <th><span>*</span>电子邮箱：</th>
                                    <td><input type="email" id="email" name="profile.pro_email" placeholder="请输入您的邮箱" onblur="emailCheck()" value="${comp.profile.pro_email }">

                                    </td>

                                    <td class="warning" id="email-warn"></td>
                                </tr>
                                <tr>
                                    <th><span>*</span>企业地址：</th>
                                    <td>
                                    <textarea style=" resize: none; height: 35px; padding: 5px; overflow-y: hidden;"
                                              id="place" placeholder="请输入企业所在地址" onblur="placeCheck()" name="profile.pro_address">${comp.profile.pro_address }</textarea>
                                        <input type="hidden" id="place2" name="pro_address" value="${comp.profile.pro_address }">
                                    </td>
                                    <td class="warning" id="place-warn"></td>
                                </tr>
                                <tr>
                                    <th><span>*</span>经营范围：</th>
                                    <td><textarea placeholder="请输入企业经营范围"
                                    				name="profile.pro_scope"
                                                  style=" resize: none; height: 35px; overflow-y: hidden;"
                                                  id="business" onblur="businessCheck()">${comp.profile.pro_scope }</textarea>
                                    </td>
                                    <td class="warning" id="business-warn"></td>
                                </tr>
                                <tr>
                                    <th>&nbsp;&nbsp;公司简介：</th>
                                    <td><textarea placeholder="请输入企业简介"
                                    				name="profile.pro_intro"
                                                  style="resize: none; height: 90px;  overflow-y: hidden;"
                                                  maxlength="500" id="introduce">${comp.profile.pro_intro }</textarea>
                                    </td>
                                    <td class="warning" id="introduce-warn"></td>
                                </tr>
                                <tr class="inputPic">
                                    <th class="picChange">上传营业执照：</th>
                                    <td>
                                        <div class="uploader white">
                                            <input type="text" class="filename" readonly="readonly">
                                            <input type="button" class="button" value="上传文件">
                                            <input type="file" class="files" size="30" name="upload">
                                        </div>
                                    </td>
                                    <td class="warning"></td>
                                </tr>
                            </table>
                            <input type="button" value="确认修改" class="submits" onclick="submitform()">
                        </form>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
<div class="covers"></div>
<div id="alerts">
    <h3>提示</h3>
    <h4>mima</h4>
</div>
<!------页脚------>
<jsp:include page="foot.jsp"></jsp:include>
<!------JS部分------>
<script>
    $(function () {
        $("input[type=file]").change(function () {
            $(this).parents(".uploader").find(".filename").val($(this).val());
        });
        $("input[type=file]").each(function () {
            if ($(this).val() == "") {
                $(this).parents(".uploader").find(".filename").val("请上传需要上传的文件");
            }
        });
    });

    function check(id, reg, spanId, errorInfo) {
        var flag;
        var val = document.getElementById(id).value;
        var oSpanNode = document.getElementById(spanId);
        if (reg.test(val) && val != "") {
            oSpanNode.innerHTML = "";
            flag = true;
        } else {
            oSpanNode.innerHTML = errorInfo.fontcolor("#c93d00");
            flag = false;
        }

        return flag;
    }
    function checkUser() {
        var reg = new RegExp("^.{3,30}$");
        check("username", reg, "username-warn", "请填写您的公司全称");
        getData()
    }
    function userCode() {
        var reg = new RegExp("^[A-Za-z0-9]{18}$", "i");
        check("usercode", reg, "usercode-warn", "请输入正确的公司注册代码号");
        getData()
    }
    function userPhone() {
        var reg = new RegExp("^0?(13|15|18)[0-9]{9}$");
        check("userphone", reg, "userphone-warn", "请输入正确的手机号");
    }
    function emailCheck() {
        var reg = new RegExp("^\\w+((-\\w+)|(\\.\\w+))*\\@[A-Za-z0-9]+((\\.|-)[A-Za-z0-9]+)*\\.[A-Za-z0-9]+$");
        check("email", reg, "email-warn", "请准确的填写您的邮箱");
    }
    function placeCheck() {
        var reg = new RegExp("^.{3,500}$");
        check("place", reg, "place-warn", "请输入企业具体地址");
        getData()

    }
    function businessCheck() {
        var reg = new RegExp("^.{3,500}$");
        check("business", reg, "business-warn", "请输入企业基本经营范围");
    }
    function getData() {
        var a=$("#username2").val();
        var a2=$(" #username").val();
        var b=$("#usercode2").val();
        var c=$("#place2").val();
         if($("#username").val()==a && $("#usercode").val()== b && $("#place").val()==c){
             $(".inputPic").hide();
             $(".inputPic .files").removeAttr("id");

         }
         else{
             $(".inputPic").show();
             $(".inputPic .files").attr("id","fileNames");
         }
    }
    $("form").submit(function () {
        
    });

    var autoTextarea = function (elem, extra, maxHeight) {
        extra = extra || 0;
        var isFirefox = !!document.getBoxObjectFor || 'mozInnerScreenX' in window,
            isOpera = !!window.opera && !!window.opera.toString().indexOf('Opera'),
            addEvent = function (type, callback) {
                elem.addEventListener ?
                    elem.addEventListener(type, callback, false) :
                    elem.attachEvent('on' + type, callback);
            },
            getStyle = elem.currentStyle ? function (name) {
                var val = elem.currentStyle[name];

                if (name === 'height' && val.search(/px/i) !== 1) {
                    var rect = elem.getBoundingClientRect();
                    return rect.bottom - rect.top -
                        parseFloat(getStyle('paddingTop')) -
                        parseFloat(getStyle('paddingBottom')) + 'px';
                }
                return val;
            } : function (name) {
                return getComputedStyle(elem, null)[name];
            },
            minHeight = parseFloat(getStyle('height'));


        elem.style.resize = 'none';

        var change = function () {
            var scrollTop, height,
                padding = 0,
                style = elem.style;

            if (elem._length === elem.value.length) return;
            elem._length = elem.value.length;

            if (!isFirefox && !isOpera) {
                padding = parseInt(getStyle('paddingTop')) + parseInt(getStyle('paddingBottom'));
            };
            scrollTop = document.body.scrollTop || document.documentElement.scrollTop;

            elem.style.height = minHeight + 'px';
            if (elem.scrollHeight > minHeight) {
                if (maxHeight && elem.scrollHeight > maxHeight) {
                    height = maxHeight - padding;
                    style.overflowY = 'auto';
                } else {
                    height = elem.scrollHeight - padding;
                    style.overflowY = 'hidden';
                };
                style.height = height + extra + 'px';
                scrollTop += parseInt(style.height) - elem.currHeight;
                document.body.scrollTop = scrollTop;
                document.documentElement.scrollTop = scrollTop;
                elem.currHeight = parseInt(style.height);
            };
        };

        addEvent('propertychange', change);
        addEvent('input', change);
        addEvent('focus', change);
        change();
    };
    var text1 = document.getElementById("introduce");
    var text2 = document.getElementById("business");
    var text3 = document.getElementById("place");
    autoTextarea(text1);// 调用
    autoTextarea(text2);// 调用
    autoTextarea(text3);// 调用
	
    function submitform(){
    	var a=$("#username").val();
        var b=$("#userphone").val();
        var c=$("#email").val();
        var d=$("#place").val();
        var e=$("#business").val();
        var f=$("#fileNames").val();
        var reg1=new RegExp("^.{3,20}$");
        var reg2=new RegExp("^0?(13|15|18)[0-9]{9}$");
        var reg3=new RegExp("^\\w+((-\\w+)|(\\.\\w+))*\\@[A-Za-z0-9]+((\\.|-)[A-Za-z0-9]+)*\\.[A-Za-z0-9]+$");
        var reg4=new RegExp("^.{3,20}$");
        var reg5=new RegExp("^.{3,20}$");
        if(!a.match(reg1)||a==""){
            alert("请确认用户名是否正确");
            return false
        }
        else if(!b.match(reg2)||b==""){
            alert("请确认手机号是否正确");
            return false
        }
        else if(!c.match(reg3)||c==""){
            alert("请确认邮箱是否正确");
            return false
        }
        else if(!d.match(reg4)||d==""){
            alert("请确认企业地址是否正确");
            return false
        }
        else if(!e.match(reg5)||e==""){
            alert("请确认企业经营范围是否正确");
            return false
        }
        else if(f==""){
            alert("请确认是否上传内容");
            return false
        }
        
    	  var form = new FormData(document.getElementById("formId"));
     	  $.ajax({
          url:"${pageContext.request.contextPath}/company_update",
          type:"post",
          data:form,
          processData:false,
          contentType:false,
          success:function(msg){
              setTimeout('$("#alerts").fadeOut()', 2000);
     		  popup($("#alerts"));
 	          $(" #alerts h4").text(msg);
          },
          error:function(e){
        	  setTimeout('$("#alerts").fadeOut()', 2000);
     		  popup($("#alerts"));
 	          $(" #alerts h4").text(e);
          }
      });        
    }
    
    function popup(popupName) {
        var _scrollHeight = $(document).scrollTop(),//获取当前窗口距离页面顶部高度
            _windowHeight = $(window).height(),//获取当前窗口高度
            _windowWidth = $(window).width(),//获取当前窗口宽度
            _popupHeight = popupName.height(),//获取弹出层高度
            _popupWeight = popupName.width();//获取弹出层宽度
        _posiTop = (_windowHeight - _popupHeight-150) / 2 + _scrollHeight;
        _posiLeft = (_windowWidth - _popupWeight+300) / 2;
        popupName.css({"left": _posiLeft + "px", "top": _posiTop + "px", "display": "block"});//设置position
    }

</script>
</body>
</html>
